<?php
require_once 'application/library/controller/gcLBasicAction.php';
require_once 'application/library/exception/gcExceptionDealer.php';
require_once 'application/modules/order/constant/order_constant_constant.php';
require_once 'application/modules/order/constant/order_constant_templatName.php';
require_once 'application/modules/order/services/order_services_orderListService.php';

/**
 * 订单一览Controller
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class order_orderListController extends gcLBasicAction {

    /**
     * objService
     */
    private $objService;

    /**
     * indexAction
     */
    public function indexAction(){
        $this->initMenu("3");
        $this->boolUserTypeCheck("2");
        $this->pvSetPageInfo();

        if ($this->getParam("ReturnFg")) {
            $arrParameter = sessionHelper::getPageData(order_constant_constant::ORDER_LIST);
            $this->gcView->arrSession = $arrParameter;
            if ($this->getParam("ReturnFg") == "2") {
                $arrMessage[0] = $this->getMessage("INFO-00001");
            } else if ($this->getParam("ReturnFg") == "3") {
                $arrMessage[0] = $this->getMessage("INFO-00003");
            }
            $this->setErrorMsg($arrMessage);
        }
        if (empty($arrParameter)) {
            $arrParameter = array();
            $arrParameter["curPage"] = 1;
            $arrParameter["pageSize"] = 10;
        }
        sessionHelper::setPageData(order_constant_constant::ORDER_LIST, $arrParameter);

        $this->objService=new order_services_orderListService();
        $this->gcView->intSum = $this->objService->pbGetSupplierSum();

        $intCount = $this->objService->pbGetSupplierDataCount($arrParameter);
        $objPager=$this->pagerInit($intCount, $arrParameter["curPage"], $arrParameter["pageSize"], pageSizeGroup::PAGE_SIZE_TEN, display::SHOW);
        $arrParameter["limit"] = $objPager->getLimit();
        $arrParameter["offset"] = $objPager->getOffset();

        $arrSearchData = $this->objService->pbGetSupplierData($arrParameter);


        $this->gcView->arrSearchData=$arrSearchData;
        $this->gcView->render(order_constant_templatName::ORDER_LIST);
    }

    /**
     * searchAction
     */
    public function searchAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $strFlag = $this->getParam("Flag");
            if ($strFlag == "1") {
                $arrParameter = array();
                $arrParameter["pageSize"] = $this->getParam("pageSize");
                $arrParameter["SupplierId"] = $this->getParam("SupplierId");
                $arrParameter["SupplierName"] = $this->getParam("SupplierName");
                $arrParameter["SaleTp"] = $this->getParam("SaleTp");
                $arrParameter["ProvCode"] = $this->getParam("ProvCode");
                $arrParameter["Position"] = $this->getParam("Position");
                $arrParameter["SupplierStatus"] = $this->getParam("SupplierStatus");
                $arrParameter["SupplierScale"] = $this->getParam("SupplierScale", true);
                $arrParameter["CreateDateFrom"] = $this->getParam("CreateDateFrom");
                $arrParameter["CreateDateTo"] = $this->getParam("CreateDateTo");
                $arrParameter["ContractNo"] = $this->getParam("ContractNo");
                $arrParameter["Tel"] = $this->getParam("Tel");
                $arrParameter["Mobile"] = $this->getParam("Mobile");
                $arrParameter["Fax"] = $this->getParam("Fax");
                $arrParameter["Email"] = $this->getParam("Email");
                $arrParameter["OrderCountFrom"] = $this->getParam("OrderCountFrom");
                $arrParameter["OrderCountTo"] = $this->getParam("OrderCountTo");
                sessionHelper::setPageData(order_constant_constant::ORDER_LIST, $arrParameter);
            } else {
                $arrParameter = sessionHelper::getPageData(order_constant_constant::ORDER_LIST);
                $arrParameter["pageSize"] = $this->getParam("pageSize");
                $arrParameter["orderColumn"] = $this->getParam("orderColumn");
                $arrParameter["order"] = $this->getParam("order");
                sessionHelper::setPageData(order_constant_constant::ORDER_LIST, $arrParameter);
            }
            $this->objService=new order_services_orderListService();
            $intCount = $this->objService->pbGetSupplierDataCount($arrParameter);

            $objPager=$this->getPagerParam($intCount);
            $arrParameter["limit"] = $objPager->getLimit();
            $arrParameter["offset"] = $objPager->getOffset();
            $arrSearchData = $this->objService->pbGetSupplierData($arrParameter);
            $objProv = new gcProvService();
            $arrSearchData = $objProv->getProvName($arrSearchData);

            $arrOutput = array(
                "count"      => $intCount,
                "curPage"    => $objPager->getCurPage(),
                "searchData" => $arrSearchData);
            if ($strFlag == "2") {
                $arrOutput["Parameter"] = $arrParameter;
            }
            jsonHelper::outPutJson($arrOutput);
        }else{
            echo 2;
        }
    }

    /**
     * 下载
     */
    public function downloadAction() {
        try {
            $arrParameter = sessionHelper::getPageData(order_constant_constant::ORDER_LIST);
            $this->objService = new order_services_orderListService();
//            $strDownloadPattern = $this->getParam("selDownload");

            $arrData = $this->objService->pbGetDownloadData($arrParameter);
            $strFileName  = date("YmdHis") . ".csv";
            //$csvFilePath  = configHelper::getGlobalVariable(self::TEMP_FILE_PATH) . "/";
            $csvFilePath = "C:";
            $blnCreateCSVFile = csvHelper::creatCsvFile($arrData, $strFileName, $csvFilePath);
            $this->download($csvFilePath . $strFileName);
        } catch (Exception $e) {
        }
    }

    /**
     * pvSetPageInfo
     */
    private function pvSetPageInfo(){
        $this->gcView->title                        = $this->getLabel("order_EC0004_PageTitle");
        $this->gcView->order_0001_Title         = $this->getLabel("order_0001_Title");
        $this->gcView->order_0001_Search        = $this->getLabel("order_0001_Search");
        $this->gcView->order_0001_Notice        = $this->getLabel("order_0001_Notice");
        $this->gcView->order_0001_NowSum        = $this->getLabel("order_0001_NowSum");
        $this->gcView->order_0001_Piece         = $this->getLabel("order_0001_Piece");
        $this->gcView->order_0001_Order      = $this->getLabel("order_0001_Order");
        $this->gcView->order_0001_SupplierName  = $this->getLabel("order_EC0004_SupplierName");
        $this->gcView->order_0001_GoodsName  = $this->getLabel("order_0001_GoodsName");
        $this->gcView->order_0001_CreateDate    = $this->getLabel("order_0001_CreateDate");
        $this->gcView->order_0001_Example       = $this->getLabel("order_0001_Example");
        $this->gcView->order_0001_Search        = $this->getLabel("order_0001_Search");
        $this->gcView->order_0001_SearchConditionClear  = $this->getLabel("order_0001_SearchConditionClear");
        $this->gcView->order_0001_Notice1       = $this->getLabel("order_0001_Notice1");
        $this->gcView->order_0001_Notice2       = $this->getLabel("order_0001_Notice2");
        $this->gcView->order_0001_Notice3       = $this->getLabel("order_0001_Notice3");
        $this->gcView->order_0001_Status        = $this->getLabel("order_0001_Status");
        $this->gcView->order_0001_Edit          = $this->getLabel("order_0001_Edit");
        $this->gcView->order_0001_DataDownload  = $this->getLabel("order_0001_DataDownload");
        $this->gcView->order_0001_Download      = $this->getLabel("order_0001_Download");
        $this->gcView->order_0001_Add           = $this->getLabel("order_0001_Add");
        $this->gcView->order_0001_AddNotice     = $this->getLabel("order_0001_AddNotice");
    }
}